package model.GsonMapping;

import model.BusinessCase;
import model.CalculationMethod;
import model.Method;

import java.lang.reflect.Field;
import java.util.Date;

public class ReuseResultData<T> 
{
	private BusinessCase bc;
	private String popularity;
	private Date lastUpdated;
	private T component;
	
	public ReuseResultData(BusinessCase bc, T component)
	{
		try 
		{
			setBc(bc);
			if(!component.getClass().equals(CalculationMethod.class))
			{
				Field fdLastUpdated = component.getClass().getDeclaredField("lastUpdated");
				fdLastUpdated.setAccessible(true);
				setLastUpdated((Date)fdLastUpdated.get(component));
				fdLastUpdated.setAccessible(false);
			}
			else
			{
				Method met = (Method)component;
				setLastUpdated(met.getLastUpdated());
			}
			
			setPopularity("TODO: Future implementation");
			setComponent(component);
		} 
		catch (Exception e) { e.printStackTrace();}
	}
	
	public void setComponent(T newComponent)
	{
		component = newComponent;
	}
	
	public T getComponent(){return component;}
	
	public BusinessCase getBc() {
		return bc;
	}
	public void setBc(BusinessCase bc) {
		this.bc = bc;
	}

	public String getPopularity() {
		return popularity;
	}

	public void setPopularity(String popularity) {
		this.popularity = popularity;
	}

	public Date getLastUpdated() {
		return lastUpdated;
	}

	public void setLastUpdated(Date lastUpdated) {
		this.lastUpdated = lastUpdated;
	}
}
